﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineTestBLL;
using OnlineTestModel;

namespace OnlineTestUI
{
    public partial class paperscorelist : System.Web.UI.Page
    {
        private StudentPapersBLL spb = new StudentPapersBLL();
        protected Students s = new Students();
        protected void Page_Load(object sender, EventArgs e)
        {
                if (Session["student"]!=null)
                {
                    s = (Students) Session["student"];
                }
                BindGrid(s.Id);
        }
        #region BindGrid
        private void BindGrid(int id)
        {
            // 1.设置总项数（特别注意：数据库分页一定要设置总记录数RecordCount）
            GridPaper.RecordCount = spb.GetRecordCount(" studentid ="+id);

            // 2.获取当前分页数据
            DataTable table = GetPagedDataTable();

            GridPaper.DataSource = table;

            GridPaper.DataBind();
        }


        /// <summary>
        /// 数据库分页
        /// </summary>
        /// <returns></returns>
        private DataTable GetPagedDataTable()
        {
            int pageIndex = GridPaper.PageIndex;
            int pageSize = GridPaper.PageSize;

            string sortField = GridPaper.SortField;
            string sortDirection = GridPaper.SortDirection;

            int rowbegin = pageIndex * pageSize+1;
            int rowend = (pageIndex + 1) * pageSize;
            string orderby = String.Format("{0} {1}", sortField, sortDirection);
            DataTable paperList = spb.GetListByPage("studentid="+s.Id, @orderby, rowbegin, rowend).Tables[0];

            return paperList;
        }

        #endregion

        #region Events




        protected void GridPaper_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
        {
            GridPaper.PageIndex = e.NewPageIndex;
            BindGrid(s.Id);
        }

        protected void GridPaper_Sort(object sender, FineUI.GridSortEventArgs e)
        {
            GridPaper.SortDirection = e.SortDirection;
            GridPaper.SortField = e.SortField;
            BindGrid(s.Id);
        }

        #endregion
    }
}